package com.ccepc.algmanage.controller;

import com.ccepc.algmanage.service.IdentificationRecordService;
import com.ccepc.common.core.util.R;
import com.ccepc.common.log.annotation.SysLog;
import com.ccepc.common.security.annotation.Inner;
import com.obs.services.ObsClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/algEvent")
@Slf4j
@Api(value = "algEvent", tags = "算法事件")
public class AlgEventController {
    @Value("${oss.endpoint}")
    private String endpoint;
    @Value("${oss.access-key}")
    private String accessKey;
    @Value("${oss.secret-key}")
    private String secretKey;
    @Value("${oss.bucket-name}")
    private String bucketName;

    @Resource
    private IdentificationRecordService identificationRecordService;

    @ApiOperation(value = "接收订阅消息")
    @SysLog("接收订阅消息" )
    @PostMapping("/callback")
    @Inner(value = false)
    public Object algCallBack(@RequestBody String request){
        log.info("回调成功，回调信息："+request);
        if (request == null) {
            log.info("请求参数为空");
            return R.failed("请求参数不能为空");
        }
        return identificationRecordService.saveAlgRecords(request,  new ObsClient(accessKey, secretKey, endpoint), bucketName);
    }

}
